home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
print
/
890ps.arc
/
LC890.C
next >
Wrap
Text File
|
1990-01-08
|
10KB
|
378 lines
/* Program to service print jobs. */
#define MAXQUEUE 25
#define WORK_SPACE 0x1000
#define DELAY_SCALE 18
#define TRUE 1
#define FALSE 0
#define PRINT_SERVER 0x7
#define PRINT_QUEUE 0x3
#define LPT1 0x1
#define NUL 0x0
#define ESC 0x1B
#define SP 0x20
#define _JPI_WIN_
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <netware.h>
#include <dos.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
SIGNAL UpdateSignal,
PrintSignal;
unsigned TickleTime = 7*DELAY_SCALE, /* Must be locked when accessed by other than Tickler */
CurrQueue; /* Must be locked when accessed by other than Printer */
wintype StatusWin, BlankWin;
struct { /* Must be locked when accessed by other than Updater or Printer */
char queue[25];
dword id;
char PreMode[50];
unsigned PreWait;
unsigned MidWait;
char PostMode[50];
unsigned PostWait;
char Desc[25];
int port;
wintype win;
int print;
int display;
} QueueInfo[MAXQUEUE];
windef DefWinDef = {0,0,SCREENWIDTH-1,SCREENDEPTH-1,LightGray,Black,FALSE,FALSE,FALSE,FALSE};
void out(const char *data, unsigned len, int port)
{
union REGS i_regs,o_regs;
if (port>0) {
i_regs.h.ah = 0x00;
i_regs.x.dx = port-1;
} else {
if (port<0) {
/**/ /* handle async port */
}
}
while (len!=0) {
if (*data!=0) {
if (port>0) {
i_regs.h.al = *data;
do {
int86(0x17,&i_regs,&o_regs);
} while ((o_regs.h.ah&0x01)==1);
} else {
if (port<0) {
/**/ /* handle async port */
}
}
}
data++;
len--;
}
}
void Tickler(void)
/* Must not alter TickleTime */
{
while (1) {
Delay(TickleTime);
Notify(UpdateSignal);
}
}
void Updater(void)
/* Must not alter QueueInfo */
{
unsigned queue;
word count,jobs[250],idx;
PrintJobClientStruct client;
dword size;
char desc[50];
QueueJobInfoStruct info;
int blank, found;
blank = 0;
while (1) {
if (blank >= 2) {
blank = 0;
putontop(BlankWin);
}
WAIT(UpdateSignal);
found = FALSE;
for (queue=0;queue<MAXQUEUE;queue++) {
if (QueueInfo[queue].display) {
GetQueueJobList(QueueInfo[queue].id,&count,jobs,NULL);
if (count!=0) {
hide(BlankWin);
Notify(PrintSignal);
blank = 0;
found = TRUE;
}
use(QueueInfo[queue].win);
clrscr();
for (idx=count;idx>0;idx--) {
if ((ReadQueueJobEntry(QueueInfo[queue].id,jobs[idx-1],&info,desc,NULL)==0) &&
(ReadPrintJobInfo(QueueInfo[queue].id,jobs[idx-1],&client)==0) &&
(GetQueueJobsFileSize(QueueInfo[queue].id,jobs[idx-1],&size)==0)) {
gotoxy(1,1);
insline();
if (info._JobFlags&0x20) {
cputs("~");
} else {
if (info._ServerID!=0) {
cputs("\xAF");
} else {
cputs(" ");
}
}
cprintf("%s->%s %lu",client._BannerName,desc,size);
}
}
}
}
if (!found) {
++blank;
}
}
}
void Printer(void)
/* Must not alter QueueInfo */
{
unsigned queue;
QueueJobInfoStruct info;
int file;
int len;
char buf[1024];
PrintJobClientStruct client;
dword size;
char desc[50];
use(StatusWin);
while (1) {
WAIT(PrintSignal);
queue = CurrQueue;
do {
if (QueueInfo[queue].print) {
while (ServiceQueueJobAndOpenFile(QueueInfo[queue].id,0xFFFF,&info)==0) {
Notify(UpdateSignal);
if (queue!=CurrQueue) {
cprintf(" Switching from %s to %s...",QueueInfo[CurrQueue].Desc,QueueInfo[queue].Desc);
Delay(QueueInfo[CurrQueue].MidWait*DELAY_SCALE);
out(QueueInfo[CurrQueue].PostMode,strlen(QueueInfo[CurrQueue].PostMode),QueueInfo[queue].port);
Delay(QueueInfo[CurrQueue].PostWait*DELAY_SCALE);
setframe(QueueInfo[CurrQueue].win,DOUBLEFRAME,LightGray,Black);
out(QueueInfo[queue].PreMode,strlen(QueueInfo[queue].PreMode),QueueInfo[queue].port);
Delay(QueueInfo[queue].PreWait*DELAY_SCALE);
CurrQueue = queue;
cputs("Done.\n");
setframe(QueueInfo[CurrQueue].win,DOUBLEFRAME,Black,LightGray);
}
ReadQueueJobEntry(QueueInfo[queue].id,info._JobNumber,NULL,desc,NULL);
ReadPrintJobInfo(QueueInfo[queue].id,info._JobNumber,&client);
GetQueueJobsFileSize(QueueInfo[queue].id,info._JobNumber,&size);
cprintf(" Printing %s->%s (%lu)... ",client._BannerName,client._BannerFile,size);
size = 0;
Lock();
if((file=_open("NETQ",O_RDONLY|SH_NOINHERIT|SH_DENYRW))!=-1) {
while ((len=_read(file,buf,sizeof(buf)))>0) {
Unlock();
out(buf,len,QueueInfo[queue].port);
size += len;
cprintf("\b\b\b\b\b\b\b\b\b\b%-10lu",size);
Lock();
}
_close(file);
}
Unlock();
if ((client._Flags&0x8)==0) {
out("\xC",1,QueueInfo[queue].port);
}
FinishServicingQueueJobAndFile(QueueInfo[queue].id,info._JobNumber,0);
cputs("\b\b\b\b\b\b\b\b\b\bDone. \n");
}
Notify(UpdateSignal);
}
queue++;
if (queue==MAXQUEUE) {
queue = 0;
}
} while (queue!=CurrQueue);
}
}
unsigned AddQueue(const char *queue, const char *Desc, int print)
{
unsigned idx;
wintype twin;
static abscoord x = 0,
y = 0;
dword id;
if (GetBinderyObjectID(queue,PRINT_QUEUE,&id)==0) {
for (idx=0;idx<MAXQUEUE;idx++) {
if (!QueueInfo[idx].display) {
Lock();
strcpy(QueueInfo[idx].queue,queue);
QueueInfo[idx].id = id;
strcpy(QueueInfo[idx].Desc,Desc);
twin = used();
QueueInfo[idx].win = windowopen(&DefWinDef);
change(QueueInfo[idx].win,x,y,x+33,y+5);
if (print) {
setframe(QueueInfo[idx].win,DOUBLEFRAME,LightGray,Black);
} else {
setframe(QueueInfo[idx].win,SINGLEFRAME,LightGray,Black);
}
settitle(QueueInfo[idx].win,QueueInfo[idx].Desc,LeftUpperTitle);
textcolor(White);
textbackground(Black);
clrscr();
use(twin);
x += 35;
if ((x+35)>=SCREENWIDTH) {
x = (x % 35)+2;
y += 6;
}
QueueInfo[idx].print = print;
QueueInfo[idx].display = TRUE;
break;
}
}
} else {
idx = MAXQUEUE;
}
return(idx);
}
void AddDisplayQueue(const char *queue, const char *Desc)
{
unsigned idx;
idx = AddQueue(queue,Desc,FALSE);
if (idx<MAXQUEUE) {
Unlock();
}
}
void AddPrintQueue(const char *queue, const char *PreMode, unsigned PreWait,
unsigned MidWait, const char *PostMode, unsigned PostWait,
const char *Desc, int port)
{
unsigned idx;
idx = AddQueue(queue,Desc,TRUE);
if (idx<MAXQUEUE) {
strcpy(QueueInfo[idx].PreMode,PreMode);
QueueInfo[idx].PreWait = PreWait;
QueueInfo[idx].MidWait = MidWait;
strcpy(QueueInfo[idx].PostMode,PostMode);
QueueInfo[idx].PostWait = PostWait;
QueueInfo[idx].port = port;
AttachQueueServerToQueue(QueueInfo[idx].id);
Unlock();
}
}
void CleanUp(void)
{
unsigned idx;
for (idx=0;idx<MAXQUEUE;idx++) {
if (QueueInfo[idx].display) {
if (QueueInfo[idx].print) {
DetachQueueServerFromQueue(QueueInfo[idx].id);
}
windowclose(QueueInfo[idx].win);
}
}
}
main()
{
int cont;
clrscr();
BlankWin = windowopen(&DefWinDef);
change(BlankWin,0,0,SCREENWIDTH-1,SCREENDEPTH-1);
StatusWin = windowopen(&DefWinDef);
change(StatusWin,0,0,SCREENWIDTH-1,SCREENDEPTH-1);
use(StatusWin);
gotoxy(1,25);
cputs("Login...\n");
LoginToFileServer("LC890",PRINT_SERVER,"LC890");
cputs("Attaching to queues...\n");
AddPrintQueue("POSTSCRIPT","",0,0,"",0,"PostScript",LPT1);
AddPrintQueue("POSTSCRIPTINTERACTIVE",
"statusdict begin 1 setsoftwareiomode end\x04",4,10,
"statusdict begin 1 setsoftwareiomode end\x04",4,
"PostScript Interactive",LPT1);
AddPrintQueue("DIABLO630","statusdict begin 2 setsoftwareiomode end\x04",4,
10,"\x1B\x7F\x30\x04",10,"Diablo 630",LPT1);
AddPrintQueue("LASERJET","statusdict begin 5 setsoftwareiomode end\x04",4,
10,"\x1B\x7F\x30\x04",10,"LaserJet",LPT1);
AddDisplayQueue("LABEL","Mailing Labels");
AddDisplayQueue("LABEL_2","Big Mailing Labels");
CurrQueue = 0; /* The queue mode which the printer is currently in */
setframe(QueueInfo[CurrQueue].win,DOUBLEFRAME,Black,LightGray);
Init(&UpdateSignal);
Init(&PrintSignal);
StartScheduler();
StartProcess(Updater,WORK_SPACE,1);
StartProcess(Printer,WORK_SPACE,1);
StartProcess(Tickler,WORK_SPACE,1);
cputs("Ready.\n");
cont = TRUE;
do {
while (!kbhit()) {
Delay(0);
}
switch (getch()) {
case NUL : while (kbhit()) {
getch();
}
break;
case ESC : cont = FALSE;
break;
case SP : hide(BlankWin);
break;
case '+' : Lock();
TickleTime += DELAY_SCALE;
Unlock();
break;
case '-' : Lock();
if (TickleTime>DELAY_SCALE) {
TickleTime -= DELAY_SCALE;
} else {
TickleTime = 0;
}
Unlock();
break;
}
} while (cont);
cputs("Stopping other processes...\n");
StopScheduler();
hide(BlankWin);
cputs("Detaching from queues...\n");
CleanUp();
cputs("Logging out...\n");
Logout();
cputs("Done.\n");
cursoron();
return(0);
}